﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ElectronicJournal.Admin
{
    public partial class OrganizationInformation : System.Web.UI.Page
    {
        private DB.SqlDb db;
        protected void Page_Init(object sender, EventArgs e)
        {
            db = new DB.SqlDb();
            System.Data.DataTable dt = db.Read("SELECT * FROM OrganizationInformation");
            if (dt.Rows.Count > 0)
            {
                if (CurrentId.Text.Length == 0)
                {
                    CurrentId.Text = dt.Rows[0]["OrganizationInformationId"].ToString();
                    NameAdresseeTextBox.Text = dt.Rows[0]["NameAddressee"].ToString();
                    CodePPTextBox.Text = dt.Rows[0]["CodePP"].ToString();
                    INNTextBox.Text = dt.Rows[0]["INN"].ToString();
                    NameTaxAuthorityTextBox.Text = dt.Rows[0]["NameTaxAuthority"].ToString();
                    NumberPensionKundTextBox.Text = dt.Rows[0]["NumberPensionKund"].ToString();
                    CodeOKATOTextBox.Text = dt.Rows[0]["CodeOKATO"].ToString();
                    SettlementAccountTextBox.Text = dt.Rows[0]["SettlementAccount"].ToString();
                    PersonalAccountNumberTextBox.Text = dt.Rows[0]["PersonalAccountNumber"].ToString();
                    NameBankTextBox.Text = dt.Rows[0]["NameBank"].ToString();
                    BIKTextBox.Text = dt.Rows[0]["BIK"].ToString();
                    KBKTextBox.Text = dt.Rows[0]["KBK"].ToString();
                    NamePaymentTextBox.Text = dt.Rows[0]["NamePayment"].ToString();
                    CorrespondentAccountTextBox.Text = dt.Rows[0]["CorrespondentAccount"].ToString();
                }

            }
        }

        protected void UpdateInformation(object sender, EventArgs e)
        {
            string query = String.Format("UPDATE OrganizationInformation SET NameAddressee = '{0}', CodePP = '{1}', INN = '{2}', NameTaxAuthority = '{3}', NumberPensionKund = '{4}', CodeOKATO = '{5}', SettlementAccount = '{6}', PersonalAccountNumber = '{7}', NameBank = '{8}', BIK = '{9}', KBK = '{10}', NamePayment = '{11}', CorrespondentAccount = '{12}' WHERE OrganizationInformationId = '{13}'",
                NameAdresseeTextBox.Text, CodePPTextBox.Text, INNTextBox.Text, NameTaxAuthorityTextBox.Text, NumberPensionKundTextBox.Text,
                CodeOKATOTextBox.Text, SettlementAccountTextBox.Text, PersonalAccountNumberTextBox.Text,
                NameBankTextBox.Text,
                BIKTextBox.Text,
                KBKTextBox.Text,
                NamePaymentTextBox.Text,
                CorrespondentAccountTextBox.Text, CurrentId.Text);
            db.Query(query);
            CurrentId.Text = null;
            Response.Redirect("~/Admin/OrganizationInformation.aspx");
        }
    }
}